
/// 泛型参数
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct GenericParam {
    /// 参数名称
    pub name: String,
}

/// 泛型类型
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct GenericType {
    /// 类型名称
    pub name: String,
    /// 泛型参数
    pub params: Vec<GenericParam>,
}

impl GenericType {
    /// 创建新的泛型类型
    pub fn new(name: String, params: Vec<GenericParam>) -> Self {
        GenericType { name, params }
    }

    /// 获取泛型参数数量
    pub fn param_count(&self) -> usize {
        self.params.len()
    }

    /// 检查是否是泛型类型
    pub fn is_generic(&self) -> bool {
        !self.params.is_empty()
    }
}

/// 泛型实例化
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct GenericInstance {
    /// 泛型类型
    pub generic_type: GenericType,
    /// 类型参数
    pub type_params: Vec<String>,
}

impl GenericInstance {
    /// 创建新的泛型实例化
    pub fn new(generic_type: GenericType, type_params: Vec<String>) -> Self {
        GenericInstance {
            generic_type,
            type_params,
        }
    }

    /// 检查类型参数数量是否匹配
    pub fn is_valid(&self) -> bool {
        self.generic_type.param_count() == self.type_params.len()
    }

    /// 获取实例化后的类型名称
    pub fn get_instance_name(&self) -> String {
        if self.type_params.is_empty() {
            self.generic_type.name.clone()
        } else {
            format!("{}<{}>", 
                self.generic_type.name, 
                self.type_params.join(", "))
        }
    }
}
